﻿using System;
using System.Collections.Generic;
using System.Text;
using NLBS.Entity;
using NLBS.Data.Business;
using NLBS.Web;
using NLBS.Framework;

namespace NLBS.Views
{
    public class FirstContentPresenter : Presenter<IFirstContentView>
    {
        public FirstContentPresenter() { }

        public override void OnViewInitialized()
        {
            // TODO: Implement code that will be executed the first time the view loads
        }

        public override void OnViewLoaded()
        {
            if (View.articleID < 0) return;
          

            Article art = ArticleData.GetArticleByID(View.articleID);
            if (art != null)
            {
                art.Category = CategoryData.GetCategoryByID(art.CategoryID);
            }
            ArticleSelectEventArgs argSelecting = new ArticleSelectEventArgs(art);
            OnSelecting(argSelecting);
            List<Article> artList = new List<Article>();
            artList.Add(argSelecting.CurrentArticle);
            View.contentList = artList;
            View.articleView=ViewHelp.checkViewPermission(art);
            View.commentView = BlogInfo.Instance().EnableComment == 1 && !art.Locked;
            OnSelected(new ArticleSelectEventArgs(argSelecting.CurrentArticle));
        }

        public static event EventHandler<ArticleSelectEventArgs> Selecting;

        public static event EventHandler<ArticleSelectEventArgs> Selected;

        protected virtual void OnSelecting(ArticleSelectEventArgs e)
        {
           
            if (Selecting != null)
            {
                Selecting(this, e);
            }
        }



        protected virtual void OnSelected(ArticleSelectEventArgs e)
        {
            if (Selected != null)
            {
                Selected(this, e);
            }
            
        }
    }
}
